﻿Type=Activity
Version=3.15
@EndOfDesignText@
#Region  Activity Attributes 
	#FullScreen: False
	#IncludeTitle: True
#End Region

Sub Process_Globals
	'These global variables will be declared once when the application starts.
	'These variables can be accessed from all modules.
	Dim V_XM As String
	Dim V_CH As String
	Dim V_BHID As Int
	Dim V_BLID As Int
	Dim FBLID As Int
	Dim FBLData As String
	Dim FBTList As List
End Sub

Sub Globals
	'These global variables will be redeclared each time the activity is created.
	'These variables can only be accessed from this module.

	Dim wbvBLNR As WebView
	
	Dim HttpJobTool As HttpJob
	Dim lsvMemu As ListView
	Dim pnlMenu As Panel
	Dim pnlTop As Panel
	Dim lblSM As Label
	Dim btnExit As Button
	Dim pnlView As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
	Activity.LoadLayout("FormBHBLNRInfo")
	
	Activity.Title = "病人病历文书内容信息-"  & V_CH & " " &V_XM 
	
	InitLayOut

End Sub

Sub Activity_Resume
	If FBLID<>V_BLID Then
		RefreshData
	Else
		wbvBLNR.LoadHtml(FBLData)
		SetTitleList(FBTList)
	End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub InitLayOut
	pnlView.Visible = False
	
	lsvMemu.SingleLineLayout.ItemHeight = PublicVar.GV_ListView_ItemHeight * 2
	lsvMemu.SingleLineLayout.Label.TextSize = PublicVar.GV_ListView_TextSize2
	'lsvMemu.ScrollingBackgroundColor = Colors.Black
	
	lblSM.TextSize = PublicVar.GV_ListView_TextSize2 + 2
	btnExit.TextSize = PublicVar.GV_ListView_TextSize2 
	
	'高级菜单
	'Activity.AddMenuItem("查看段落","MenuItemAdv")
End Sub

Sub RefreshData
	Dim sURL,sSession,sBHID,sBLID,sText As String
	
	sSession = PublicVar.GV_DesTool.Base64encrypt(PublicVar.GV_UserSession)
	
	sBHID = PublicVar.GV_DesTool.Base64encrypt(V_BHID)
	sBLID = PublicVar.GV_DesTool.Base64encrypt(V_BLID)
	
	sText = "Session=" & sSession & "&BHID=" & sBHID & "&BLID=" & sBLID

	sURL = PublicVar.GetServerUrl&"/getbhblnrinfo"
	HttpJobTool.Initialize("Job1",Me)
	HttpJobTool.PostString(sURL,sText)
	ProgressDialogShow("正在获取数据，请稍候...")	

End Sub

Sub JobDone (Job As HttpJob)
   Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
   If Job.Success = True Then
      If Job.JobName = "Job1" Then
				HttpJobSuccess(Job)
      End If
   Else
		HttpJobError(Job)
   End If
   Job.Release
End Sub

Sub HttpJobSuccess(Job As HttpJob)
	Dim sResult,sCode,sData,sHtml,sAdd As String
	Dim iPos0,iPos1 As Int
	Dim mapResult As Map
	
	ProgressDialogHide
	sResult = Job.GetString.Trim
	
	PublicVar.GV_JSonTool.Initialize(sResult)
	mapResult = PublicVar.GV_JSonTool.NextObject
	
	sCode = mapResult.Get("Code")
	If sCode<>"0" Then
		sResult = mapResult.Get("Message")
		ToastMessageShow("获取数据失败"&CRLF &sResult, True)	
		
		PublicVar.CheckSession(sCode)
		Return
	End If
	
	sData = mapResult.Get("Data")
	If sData ="" Then
		ToastMessageShow("获取数据失败"&CRLF &"返回的数据为空", True)	
		Return	
	
	End If
	
	sData = PublicVar.GV_DesTool.Base64decrypt(sData)
	sHtml = sData
	iPos0 = sData.IndexOf(PublicVar.GV_HTML_ADD_DATA_BEGIN)
	If iPos0 > -1 Then
		iPos1 = sData.IndexOf(PublicVar.GV_HTML_ADD_DATA_END)
		sHtml = sData.SubString2(0,iPos0) 	
		sAdd = sData.SubString2(iPos0+PublicVar.GV_HTML_ADD_DATA_BEGIN.Length,iPos1)
	End If
	
	wbvBLNR.LoadHtml(sHtml)
	FBLData = sHtml
	FBLID = V_BLID
	
	If sAdd.Length >0 Then
		PublicVar.GV_JSonTool.Initialize(sAdd)
		FBTList = PublicVar.GV_JSonTool.NextArray		
		SetTitleList(FBTList)
	Else
		SetMenuLayOut(0)
	End If
	
End Sub

Sub HttpJobError(Job As HttpJob)  
	Dim sMsg As String
	ProgressDialogHide
		
	Log("Error: " & Job.ErrorMessage)
	sMsg = "获取病历文书内容失败."& CRLF & Job.ErrorMessage 
  ToastMessageShow(sMsg, True)
End Sub

Sub SetTitleList(AList As List)
	Dim mapResult As Map
	Dim sTitle As String
	Dim iCount As Int
	lsvMemu.Clear
	
	iCount = AList.Size
	For i = 0 To iCount - 1 
		mapResult = AList.Get(i)
		sTitle = i + 1
		sTitle = sTitle & " "& mapResult.Get("title")
		lsvMemu.AddSingleLine2(sTitle,mapResult.Get("title"))

	Next
	
	lblSM.Text = "共有"&iCount&"个段落"
	
	If iCount>5 Then	
		iCount = 5
		SetMenuLayOut(iCount)
	Else If iCount>0 Then
		iCount = iCount + 1		
	End If
	
	SetMenuLayOut(iCount)
End Sub

Sub lsvMemu_ItemClick (Position As Int, Value As Object)
	Dim elemId As String
	elemId = Value
	wbvBLNR.loadUrl("javascript:scrollToElement('" &elemId &"')")
	pnlView.Visible = False
End Sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
	If KeyCode = KeyCodes.KEYCODE_MENU Then
		pnlView.Visible = True
		pnlView.BringToFront
		
		Return True
	Else If KeyCode = KeyCodes.KEYCODE_BACK Then
		If pnlView.Visible =True Then
			pnlView.Visible = False
			Return True
		Else
			Return False
		End If
	
	Else
		Return False
	End If
End Sub

Sub SetMenuLayOut(AMenuCount As Int)
	pnlView.Visible = False		
	
	pnlMenu.Height = lsvMemu.SingleLineLayout.ItemHeight * AMenuCount
	pnlMenu.Top = 100%Y - pnlMenu.Height
	
	pnlTop.Height = lsvMemu.SingleLineLayout.ItemHeight 
	
	lsvMemu.Top = pnlTop.Height
	lsvMemu.Height = pnlMenu.Height - lsvMemu.Top
	
	btnExit.Left = pnlTop.Width - btnExit.Width
	btnExit.Height = pnlTop.Height

	lblSM.Height = pnlTop.Height
	lblSM.Width = pnlTop.Width - btnExit.Width

	
End Sub

Sub btnExit_Click
	pnlView.Visible = False

End Sub

Sub pnlView_Click
	pnlView.Visible = False
End Sub